{% extends 'inquire/base.html' %}

{% block title %}
    用户增删改区
{% endblock %}

{% block startbody %}
    <form action="{% url 'add_user:add_user' %}?uid={{ user_obj.id|default:'' }}" method="post">
    {% csrf_token %}
        <div class="container-fluid" style="margin: 30px 0 0">
            <div class="row">
                <div class="col-md-3" style="margin: 18px 0;"></div>
                <div class="col-md-6" style="margin: 18px 0;">
                    <label for="basic-url">用户名</label>
                    <div class="input-group input-group-lg">
                        <span class="input-group-addon" id="basic-addon1">></span>
                        <input type="text" class="form-control" placeholder="Username" aria-describedby="basic-addon1"
                               value="{{ user_obj.name|default:'' }}" maxlength="20" name="user" required>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-md-3" style="margin: 18px 0;"></div>
                <div class="col-md-6" style="margin: 18px 0;">
                    <label for="basic-url">密码</label>
                    <div class="input-group input-group-lg">
                        <span class="input-group-addon">></span>
                        <input type="password" class="form-control" aria-label="Amount (to the nearest dollar)"
                               maxlength="6" name="pswd" required>
                        <span class="input-group-addon">6位</span>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-md-3" style="margin: 18px 0;"></div>
                <div class="col-md-3" style="margin: 18px 0;">
                    <label>性别</label>
                    <div class="row">
                      <div class="col-lg-6">
                        <div class="input-group">
                          <span class="input-group-addon">
                            <input type="radio" aria-label="..." name="sex" value="1" {% if user_obj.sex.id == 1 %}
                                   checked {% endif %} required>
                          </span>
                          <input type="text" class="form-control" aria-label="..." value="男" disabled>
                        </div><!-- /input-group -->
                      </div><!-- /.col-lg-6 -->
                      <div class="col-lg-6">
                        <div class="input-group">
                          <span class="input-group-addon">
                            <input type="radio" aria-label="..." name="sex" value="" {% if user_obj.sex.id == 2 %}
                                   checked {% endif %} required>
                          </span>
                          <input type="text" class="form-control" aria-label="..." value="女" disabled>
                        </div><!-- /input-group -->
                      </div><!-- /.col-lg-6 -->
                    </div><!-- /.row -->
                </div>

                <div class="col-md-3" style="margin: 18px 0;">
                    <label for="exampleInputEmail">职务</label><br>
                    {% for foo in list_duty %}
                        <label class="checkbox-inline">
                          <input type="checkbox" id="inlineCheckbox1" name="dutys" value="{{ foo.id }}"
                          {% if foo.id in user_duty %} checked {% endif %}> {{ foo.duty }}
                        </label>
                    {% endfor %}

                </div>
            </div>

            <div class="row">
                <div class="col-md-5" style="margin: 18px 0;"></div>
                {% if user_obj %}
                <div class="col-md-1">
                    <button type="submit" class="btn btn-default">Submit</button>
                </div>
                <div class="col-md-1">
                    <a class="btn btn-danger" href="{% url 'add_user:delete_user' %}?uid={{ user_obj.id }}">删除</a>
                </div>
                    {% else %}
                <div class="col-md-2" style="margin: 18px 100px;">
                    <button type="submit" class="btn btn-default">Submit</button>
                </div>
                {% endif %}
            </div>
        </div>
    </form>
{% endblock %}

{% block css_js %}
    <script>
        {% if mes %}
            alert('{{ mes }}');
        {% endif %}
    </script>
{% endblock %}